<?php

namespace App\Http\Controllers;

use App\Article;
use App\ArticleType;
use App\Product;
use App\ProductType;

class ContentController extends Controller
{
    public function product($id)
    {
        $product = Product::find($id);
        if (!isset($product->id)) {
            return redirect('/');
        }
        $productTypes = ProductType::orderBy('sort', 'asc')
            ->get();
        return view('product.content', [
            'product' => $product,
            'productTypes' => $productTypes
        ]);
    }

    public function article($id)
    {
        $productTypes = ProductType::orderBy('sort', 'asc')
            ->get();
        $article = Article::find($id);
        return view('article.content', [
            'article' => $article,
            'productTypes' => $productTypes
        ]);
    }

    public function articleType($id)
    {
        $productTypes = ProductType::orderBy('sort', 'asc')
            ->get();
        $articleType = ArticleType::find($id);
        return view('article_type.content', [
            'articleType' => $articleType,
            'productTypes' => $productTypes
        ]);
    }

    public function articleTypeImg($id)
    {
        $productTypes = ProductType::orderBy('sort', 'asc')
            ->get();
        $articleType = ArticleType::find($id);
        return view('article_type.content_img', [
            'articleType' => $articleType,
            'productTypes' => $productTypes
        ]);
    }
}